import requests
import os
import re
from bs4 import BeautifulSoup
import qqmusicdownload

# with open('D:\page\zhihupage.txt','r',encoding='utf-16le') as zhihu:
#     b = zhihu.readlines()
#     result = []
#     for line in b:
#         print(line)
#         pattern = re.compile(r'《.+?》')
#         result = re.findall(pattern, line)
#     qq_music = qqmusicdownload.Music_tx()
#     for item in result:
#         qq_music.search_music(item)

header = {
            'Connection': "keep-alive",
            'Pragma': "no-cache",
            'Cache-Control': "no-cache",
            'User-Agent': "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) "
                          "Chrome/72.0.3626.119 Safari/537.36",
            'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
            'Accept-Encoding': "gzip, deflate",
            'Accept-Language': "zh-CN,zh;q=0.9",
            'cache-control': "no-cache",
        }
res = requests.get(r'https://music.douban.com/tag/%E6%8E%A8%E8%8D%90',headers=header)
html = BeautifulSoup(res.text,'html.parser')
print(html.title)
a = html.find_all("a", class_="nbg")
music_name = []
for ele in a:
    print(ele.get("title"))
    music_name.append(ele.get("title"))
qq_music = qqmusicdownload.Music_tx()
for item in music_name:
    qq_music.search_music(item)